<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="118px">
      <el-form-item label="订单号" prop="ddh">
        <el-input
          v-model="queryParams.ddh"
          placeholder="请输入订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料编码" prop="wlbm">
        <el-input
          v-model="queryParams.wlbm"
          placeholder="请输入物料编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料名称" prop="wlmc">
        <el-input
          v-model="queryParams.wlmc"
          placeholder="请输入物料名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="单位" prop="dw">
        <el-input
          v-model="queryParams.dw"
          placeholder="请输入单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="数量" prop="sl">
        <el-input
          v-model="queryParams.sl"
          placeholder="请输入数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="下单日期">
        <el-date-picker
          v-model="daterangeXdrq"
          style="width: 209px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="交货日期">
        <el-date-picker
          v-model="daterangeJhrq"
          style="width: 209px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <!-- <el-form-item label="规格要求" title="规格要求(下级零件,板厚,单件用量等)" prop="ggyq">
        <el-input
          v-model="queryParams.ggyq"
          placeholder="请输入规格要求(下级零件,板厚,单件用量等)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工艺路线" prop="gylx">
        <el-input
          v-model="queryParams.gylx"
          placeholder="请输入工艺路线"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="加工工序" prop="jjggx">
        <el-input
          v-model="queryParams.jjggx"
          placeholder="请输入机加工工序"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="重量" prop="zl">
        <el-input
          v-model="queryParams.zl"
          placeholder="请输入重量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="客户名称" prop="khmc">
        <el-input
          v-model="queryParams.khmc"
          placeholder="请输入客户名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="供应商" prop="deptName">
        <el-input
          v-model="queryParams.deptName"
          placeholder="请输入供应商名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="订单备注" prop="ddbz">
        <el-input
          v-model="queryParams.ddbz"
          placeholder="请输入订单备注"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="订单类型" prop="ddlx">
        <el-select v-model="queryParams.ddlx" placeholder="请选择订单类型" clearable>
          <el-option
            v-for="dict in dict.type.sys_ddlx"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="物料类型" prop="wllx">
        <el-select v-model="queryParams.wllx" placeholder="请选择物料类型" clearable>
          <el-option
            v-for="dict in dict.type.sys_wllx"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="物料审核状态" prop="wlshzt1">
        <el-select v-model="queryParams.wlshzt1" placeholder="请选择物料审核状态" clearable>
          <el-option
            v-for="dict in dict.type.sys_shzt"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item> -->

     <!-- <el-form-item label="入库状态" prop="rkzt">
        <el-select v-model="queryParams.rkzt" placeholder="请选择入库状态" clearable>
          <el-option
            v-for="dict in dict.type.sys_rkzt"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="入库时间" prop="rksj">
        <el-input
          v-model="queryParams.rksj"
          placeholder="请输入入库时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="出库状态" prop="ckzt">
        <el-select v-model="queryParams.ckzt" placeholder="请选择出库状态" clearable>
          <el-option
            v-for="dict in dict.type.sys_ckzt"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="出库时间" prop="cksj">
        <el-input
          v-model="queryParams.cksj"
          placeholder="请输入出库时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="订单状态" prop="ddzt">
        <el-select v-model="queryParams.ddzt" placeholder="请选择订单状态" clearable>
          <el-option
            v-for="dict in dict.type.sys_ddzt"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['ddgl:export']"
        >导出</el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-download"
          size="mini"
          @click="exportChd"
          v-hasPermi="['ddgl:exportChd']"
        >导出出货单</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          v-hasPermi="['jhgl:import']"
        >出入库导入</el-button>
      </el-col>

      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading"
    border
        	style="width: 130%"
        	:header-cell-style="{ fontSize: '13px', color: '#555',textAlign: 'center',background:'#E0E9F0' }"
        	:cell-style="{ textAlign: 'center' }"
    :data="ddglList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" fixed />
      <el-table-column label="订单号" align="center" prop="ddh" width="126"  fixed />
      <el-table-column label="物料编码" align="center" prop="wlbm" width="160" fixed />
      <el-table-column label="物料名称" align="center" prop="wlmc" width="180" fixed />
      <el-table-column label="单位" align="center" prop="dw" width="55"/>
      <el-table-column label="订单总量" align="center" prop="sl" width="75" />
      <el-table-column label="消库存量" align="center" prop="dhsXkcsl" width="75" />
      <el-table-column label="入库量" align="center" prop="rksl" width="75" />
        <el-table-column label="订单总量(供应商)" align="center" prop="dhsSjxzddsl" width="100" />
      <el-table-column label="出货信息">
        <el-table-column label="已出货数量" align="center" prop="chsl" width="90"/>
        <el-table-column label="待出货数量" align="center" prop="dchsl" width="100"/>
      </el-table-column>
      <el-table-column label="入库出库信息">
      <el-table-column label="已入库数量" align="center" prop="rksl" width="90">
        <template slot-scope="scope">
          <span>{{scope.row.rksl-scope.row.dhsXkcsl }}</span>
        </template>
      </el-table-column>
      <el-table-column label="待入库数量" align="center" prop="drksl" width="90" >
          <template slot-scope="scope">
            <span>{{  scope.row.dhsSjxzddsl-scope.row.rksl+scope.row.dhsXkcsl }}</span>
          </template>
      </el-table-column>
      </el-table-column>

      <el-table-column label="下单日期" align="center" prop="xdrq" width="110">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.xdrq, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="125">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleUpdateXq(scope.row)"
            v-hasPermi="['ddgl:detail']"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-setting"
            @click="handleUpdateCh(scope.row)"
            v-hasPermi="['ddgl:jgsz']"
            :disabled="scope.row.zbjgshzt1=='1'||scope.row.zbjgshzt1=='0' "
          >出货</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 对话框1，添加或修改对话框、查看详情对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="980px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="130px">
         <!--1，计划/订单信息 -->
        <el-form-item label="订单号" prop="ddh">
          <el-input v-model="form.ddh" placeholder="请输入订单号" :disabled="isCkxqShow" />
        </el-form-item>
        <el-form-item label="物料编码" prop="wlbm">
          <el-input v-model="form.wlbm" placeholder="请输入物料编码" :disabled="isCkxqShow"/>
        </el-form-item>
        <el-form-item label="物料名称" prop="wlmc">
          <el-input v-model="form.wlmc" placeholder="请输入物料名称" :disabled="isCkxqShow"/>
        </el-form-item>
        <el-form-item label="单位" prop="dw">
          <el-input v-model="form.dw" placeholder="请输入单位" :disabled="isCkxqShow"/>
        </el-form-item>
        <el-form-item label="订单总量" prop="sl">
          <el-input v-model="form.sl" placeholder="请输入数量" :disabled="isCkxqShow"/>
        </el-form-item>
        <el-form-item label="消库存数量" prop="dhsXkcsl">
          <el-input v-model="form.dhsXkcsl" placeholder="消库存数量" :disabled="isCkxqShow"/>
        </el-form-item>
        <el-form-item label="实际新增订单量" prop="dhsSjxzddsl">
          <el-input v-model="form.dhsSjxzddsl" placeholder="实际新增订单量" :disabled="isCkxqShow"/>
        </el-form-item>
        <el-form-item label="已入库数量" prop="rksl">
          <el-input v-model="form.rksl" placeholder="已入库数量" :disabled="isCkxqShow"/>
        </el-form-item>
        <el-form-item label="待入库数量" prop="drksl">
          <el-input v-model="form.drksl" placeholder="待入库数量" :disabled="isCkxqShow"/>
        </el-form-item>
        <el-form-item label="已出库数量" prop="cksl">
          <el-input v-model="form.cksl" placeholder="已出库数量" :disabled="isCkxqShow"/>
        </el-form-item>
        <el-form-item label="待出库数量" prop="dcksl">
          <el-input v-model="form.dcksl" placeholder="待出库数量" :disabled="isCkxqShow"/>
        </el-form-item>

        <el-form-item label="下单日期" prop="xdrq">
          <el-date-picker clearable  :disabled="isCkxqShow"
            v-model="form.xdrq"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择下单日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="交货日期" prop="jhrq">
          <el-date-picker clearable :disabled="isCkxqShow"
            v-model="form.jhrq"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择交货日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="规格要求" prop="ggyq">
          <el-input v-model="form.ggyq" placeholder="请输入规格要求(下级零件,板厚,单件用量等)" :disabled="isCkxqShow"/>
        </el-form-item>
        <el-form-item label="工艺路线" prop="gylx">
          <el-input v-model="form.gylx" placeholder="请输入工艺路线" :disabled="isCkxqShow"/>
        </el-form-item>
        <el-form-item label="机加工工序" prop="jjggx">
          <el-input v-model="form.jjggx" placeholder="请输入机加工工序" :disabled="isCkxqShow"/>
        </el-form-item>
        <el-form-item label="重量" prop="zl">
          <el-input v-model="form.zl" placeholder="请输入重量" :disabled="isCkxqShow"/>
        </el-form-item>
        <el-form-item label="客户名称" prop="khmc">
          <el-input v-model="form.khmc" placeholder="请输入客户名称" :disabled="isCkxqShow"/>
        </el-form-item>
        <!-- <el-form-item label="订货商机构代码" prop="dhsDeptId">
          <el-input v-model="form.dhsDeptId" placeholder="请输入订货商机构代码,导入此订单的用户所属机构代码" />
        </el-form-item> -->
        <el-form-item label="供应商名称" prop="deptName">
          <el-input v-model="form.deptName" placeholder="请输入供应商部门名称(从部门下拉选择)" :disabled="isCkxqShow"/>
        </el-form-item>
       <!-- <el-form-item label="供应商部门ID" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入供应商部门ID" />
        </el-form-item> -->

        <el-form-item label="订单类型" prop="ddlx">
          <el-select v-model="form.ddlx" placeholder="请选择订单类型" :disabled="isCkxqShow">
            <el-option
              v-for="dict in dict.type.sys_ddlx"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="物料类型" prop="wllx">
          <el-select v-model="form.wllx" placeholder="请选择物料类型" :disabled="isCkxqShow">
            <el-option
              v-for="dict in dict.type.sys_wllx"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>

        <!-- <el-form-item label="外协订单ID,对于外协转自制的记录" prop="wxddid">
          <el-input v-model="form.wxddid" placeholder="请输入外协订单ID,对于外协转自制的记录" />
        </el-form-item> -->
        <!-- 2，供应商维护价格信息 -->
        <el-form-item label="供应商单价" prop="ghsdj" v-show="isCkxqShow">
          <el-input v-model="form.ghsdj" placeholder="请输入供应商单价,由供应商维护" :disabled="isCkxqShow"/>
        </el-form-item>
        <el-form-item label="供应商总价" prop="ghszj" v-show="isCkxqShow">
          <el-input v-model="form.ghszj" placeholder="请输入供应商总价,系统自动计算" :disabled="isCkxqShow"/>
        </el-form-item>
        <el-form-item label="备注" prop="ddbz">
          <el-input type="textarea" v-model="form.ddbz" placeholder="请输入订单备注" :disabled="isCkxqShow"/>
        </el-form-item>
        <!-- <el-form-item label="供货商价格备注" prop="ghsjgbz" v-show="isCkxqShow">
          <el-input v-model="form.ghsjgbz" placeholder="请输入供货商价格备注" :disabled="isCkxqShow"/>
        </el-form-item> -->
        <!-- <el-form-item label="供应商价格维护人" prop="ghsjgwhr">
          <el-input v-model="form.ghsjgwhr" placeholder="请输入供应商价格维护人" />
        </el-form-item>
        <el-form-item label="供货商价格维护时间" prop="ghsjgwhsj">
          <el-input v-model="form.ghsjgwhsj" placeholder="请输入供货商价格维护时间" />
        </el-form-item> -->
        <!-- 3，总部价格审核 -->
        <!-- <el-form-item label="总部价格审核状态" prop="zbjgshzt1" v-show="isCkxqShow">
          <el-radio-group v-model="form.zbjgshzt1" >
            <el-radio   :disabled="isCkxqShow"
              v-for="dict in dict.type.sys_shzt"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="总部价格审核意见" prop="zbjgsh1shyj" v-show="isCkxqShow">
          <el-input type="textarea" v-model="form.zbjgsh1shyj" placeholder="请输入总部价格审核意见" :disabled="isCkxqShow"/>
        </el-form-item> -->
        <!-- <el-form-item label="总部价格审核时间" prop="zbjgsh1shsj">
          <el-input v-model="form.zbjgsh1shsj" placeholder="请输入总部价格审核时间" />
        </el-form-item> -->

         <!-- 4，补料审核 -->
        <!-- <el-form-item label="物料审核状态" prop="wlshzt1">
          <el-radio-group v-model="form.wlshzt1">
            <el-radio
              v-for="dict in dict.type.sys_shzt"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item> -->
        <!-- <el-form-item label="物料审核更新时间" prop="wlsh1gxsj">
          <el-input v-model="form.wlsh1gxsj" placeholder="请输入物料审核更新时间" />
        </el-form-item> -->
        <!-- 5，入库出库操作 -->
        <!-- <el-form-item label="入库状态" prop="rkzt" v-show="isCkxqShow">
          <el-radio-group v-model="form.rkzt">
            <el-radio
              v-for="dict in dict.type.sys_rkzt" :disabled="isCkxqShow"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="入库时间" prop="rksj" v-show="isCkxqShow">
          <el-input v-model="form.rksj" placeholder="请输入入库时间" :disabled="isCkxqShow"/>
        </el-form-item>
        <el-form-item label="入库人" prop="rkr" v-show="isCkxqShow" >
          <el-input v-model="form.rkr" placeholder="请输入入库人" :disabled="isCkxqShow"/>
        </el-form-item>
        <el-form-item label="出库状态" prop="ckzt" v-show="isCkxqShow">
          <el-radio-group v-model="form.ckzt">
            <el-radio
              v-for="dict in dict.type.sys_ckzt" :disabled="isCkxqShow"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item> -->
        <!-- <el-form-item label="出库备注" prop="ckbz">
          <el-input v-model="form.ckbz" placeholder="请输入出库备注" />
        </el-form-item> -->
        <!-- <el-form-item label="出库时间" prop="cksj" v-show="isCkxqShow">
          <el-input v-model="form.cksj" placeholder="请输入出库时间" :disabled="isCkxqShow"/>
        </el-form-item>
        <el-form-item label="出库人" prop="ckr" v-show="isCkxqShow">
          <el-input v-model="form.ckr" placeholder="请输入出库人" :disabled="isCkxqShow"/>
        </el-form-item>
        <el-form-item label="订单状态" prop="ddzt" v-show="isCkxqShow">
          <el-select v-model="form.ddzt" placeholder="请选择订单整体状态" :disabled="isCkxqShow">
            <el-option
              v-for="dict in dict.type.sys_ddzt"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item> -->
       <!-- <el-form-item label="是否删除" prop="sfsc">
          <el-radio-group v-model="form.sfsc">
            <el-radio
              v-for="dict in dict.type.sys_yw_shifou"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item> -->
        <!-- <el-form-item label="是否已开发票" prop="sfykp">
          <el-radio-group v-model="form.sfykp">
            <el-radio
              v-for="dict in dict.type.sys_yw_shifou"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="发票ID" prop="fpid">
          <el-input v-model="form.fpid" placeholder="请输入发票ID" />
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" v-show="!isCkxqShow" >确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 对话框2，价格设置对话框 -->
    <el-dialog :title="title" :visible.sync="openJgsz" width="980px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="130px">
         <!--1，计划/订单信息 -->
        <el-form-item label="订单号" prop="ddh" >
          <el-input v-model="form.ddh" placeholder="请输入订单号" :disabled="isJgwhShow" />
        </el-form-item>
        <el-form-item label="物料编码" prop="wlbm">
          <el-input v-model="form.wlbm" placeholder="请输入物料编码" :disabled="isJgwhShow"/>
        </el-form-item>
        <el-form-item label="物料名称" prop="wlmc">
          <el-input v-model="form.wlmc" placeholder="请输入物料名称" :disabled="isJgwhShow"/>
        </el-form-item>
        <el-form-item label="单位" prop="dw" >
          <el-input v-model="form.dw" placeholder="请输入单位" :disabled="isJgwhShow"/>
        </el-form-item>
        <el-form-item label="数量" prop="sl">
          <el-input v-model="form.sl" placeholder="请输入数量" :disabled="isJgwhShow"/>
        </el-form-item>
        <el-form-item label="下单日期" prop="xdrq">
          <el-date-picker clearable
            v-model="form.xdrq"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择下单日期" :disabled="isJgwhShow">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="交货日期" prop="jhrq">
          <el-date-picker clearable
            v-model="form.jhrq"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择交货日期" :disabled="isJgwhShow" >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="规格要求" prop="ggyq">
          <el-input v-model="form.ggyq" placeholder="请输入规格要求(下级零件,板厚,单件用量等)" :disabled="isJgwhShow"/>
        </el-form-item>
        <el-form-item label="工艺路线" prop="gylx">
          <el-input v-model="form.gylx" placeholder="请输入工艺路线" :disabled="isJgwhShow"/>
        </el-form-item>
        <el-form-item label="机加工工序" prop="jjggx">
          <el-input v-model="form.jjggx" placeholder="请输入机加工工序" :disabled="isJgwhShow"/>
        </el-form-item>
        <el-form-item label="重量" prop="zl">
          <el-input v-model="form.zl" placeholder="请输入重量" :disabled="isJgwhShow"/>
        </el-form-item>
        <el-form-item label="客户名称" prop="khmc">
          <el-input v-model="form.khmc" placeholder="请输入客户名称" :disabled="isJgwhShow"/>
        </el-form-item>
        <!-- <el-form-item label="订货商机构代码" prop="dhsDeptId">
          <el-input v-model="form.dhsDeptId" placeholder="请输入订货商机构代码,导入此订单的用户所属机构代码" />
        </el-form-item> -->
        <el-form-item label="供应商名称" prop="deptName">
          <el-input v-model="form.deptName" placeholder="请输入供应商部门名称(从部门下拉选择)" :disabled="isJgwhShow"/>
        </el-form-item>
       <!-- <el-form-item label="供应商部门ID" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入供应商部门ID" />
        </el-form-item> -->
        <el-form-item label="备注" prop="ddbz">
          <el-input v-model="form.ddbz" placeholder="请输入订单备注" :disabled="isJgwhShow"/>
        </el-form-item>
        <el-form-item label="订单类型" prop="ddlx">
          <el-select v-model="form.ddlx" placeholder="请选择订单类型" :disabled="isJgwhShow" >
            <el-option
              v-for="dict in dict.type.sys_ddlx"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <!-- 2，供应商维护价格信息 -->
        <el-form-item label="供应商单价" prop="ghsdj"  >
          <el-input v-model="form.ghsdj" placeholder="请输入供应商单价,由供应商维护" @input="calculateValue" :disabled="!isJgshShow"/>
        </el-form-item>
        <el-form-item label="供应商总价" prop="ghszj" >
          <el-input v-model="form.ghszj" placeholder="请输入供应商总价,系统自动计算"  :disabled="true" />
        </el-form-item>
        <el-form-item label="供货商价格备注" prop="ghsjgbz" >
          <el-input type="textarea" v-model="form.ghsjgbz" placeholder="请输入供货商价格备注" :disabled="!isJgshShow" />
        </el-form-item>
        <!-- <el-form-item label="供应商价格维护人" prop="ghsjgwhr">
          <el-input v-model="form.ghsjgwhr" placeholder="请输入供应商价格维护人" />
        </el-form-item>
        <el-form-item label="供货商价格维护时间" prop="ghsjgwhsj">
          <el-input v-model="form.ghsjgwhsj" placeholder="请输入供货商价格维护时间" />
        </el-form-item> -->
        <!-- 3，总部价格审核 openJgsp -->
       <el-form-item label="总部价格审核状态" prop="zbjgshzt1">
          <el-radio-group v-model="form.zbjgshzt1"  :disabled="isJgshShow">
            <el-radio
              v-for="dict in dict.type.sys_shzt"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="总部价格审核意见" prop="zbjgsh1shyj">
          <el-input type="textarea" v-model="form.zbjgsh1shyj" placeholder="请输入总部价格审核意见" :disabled="isJgshShow"/>
        </el-form-item>
        <!-- <el-form-item label="总部价格审核时间" prop="zbjgsh1shsj">
          <el-input v-model="form.zbjgsh1shsj" placeholder="请输入总部价格审核时间" />
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" v-show="!isJgwhShow" >确 定</el-button>
        <el-button type="primary" @click="submitFormJgsz" v-show="isJgwhShow && isJgshShow" >设置提交</el-button>
        <el-button type="primary" @click="submitFormJgsh" v-show="isJgwhShow && !isJgshShow" >审核提交</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 对话框3，入库数量设置 -->
    <el-dialog :title="title" :visible.sync="openRk" width="980px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="130px">
         <!--1，计划/订单信息 -->
        <el-form-item label="订单号" prop="ddh" >
          <el-input v-model="form.ddh" placeholder="请输入订单号" :disabled="isJgwhShow" />
        </el-form-item>
        <el-form-item label="物料编码" prop="wlbm">
          <el-input v-model="form.wlbm" placeholder="请输入物料编码" :disabled="isJgwhShow"/>
        </el-form-item>
        <el-form-item label="物料名称" prop="wlmc">
          <el-input v-model="form.wlmc" placeholder="请输入物料名称" :disabled="isJgwhShow"/>
        </el-form-item>
        <el-form-item label="供应商名称" prop="deptName">
          <el-input v-model="form.deptName" placeholder="请输入供应商部门名称" :disabled="isJgwhShow"/>
        </el-form-item>
        <el-form-item label="订单数量" prop="sl">
          <el-input v-model="form.sl" placeholder="订单数量" :disabled="isJgwhShow"/>
        </el-form-item>
        <el-form-item label="已入库数量" prop="yrksl">
          <el-input v-model="form.yrksl" placeholder="已入库数量" :disabled="isJgwhShow"/>
        </el-form-item>
        <el-form-item label="入库数量" prop="rksl">
          <template>
           <el-input-number v-model="form.rksl" :min="1" :max="form.drksl"  @change="changeVal" />
          </template>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" v-show="!isJgwhShow" >确 定</el-button>
        <el-button type="primary" @click="submitFormJgsz" v-show="isJgwhShow && isJgshShow" >设置提交</el-button>
        <el-button type="primary" @click="submitFormRK" v-show="isJgwhShow && !isJgshShow" >入库提交</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 对话框4，出库数量设置 -->
    <el-dialog :title="title" :visible.sync="openCk" width="980px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="130px">
         <!--1，计划/订单信息 -->
        <el-form-item label="订单号" prop="ddh" >
          <el-input v-model="form.ddh" placeholder="请输入订单号" :disabled="isJgwhShow" />
        </el-form-item>
        <el-form-item label="物料编码" prop="wlbm">
          <el-input v-model="form.wlbm" placeholder="请输入物料编码" :disabled="isJgwhShow"/>
        </el-form-item>
        <el-form-item label="物料名称" prop="wlmc">
          <el-input v-model="form.wlmc" placeholder="请输入物料名称" :disabled="isJgwhShow"/>
        </el-form-item>
        <el-form-item label="供应商名称" prop="deptName">
          <el-input v-model="form.deptName" placeholder="请输入供应商部门名称" :disabled="isJgwhShow"/>
        </el-form-item>
        <el-form-item label="订单数量" prop="sl">
          <el-input v-model="form.sl" placeholder="订单数量" :disabled="isJgwhShow"/>
        </el-form-item>
        <el-form-item label="已出库数量" prop="ycksl">
          <el-input v-model="form.ycksl" placeholder="已出库数量" :disabled="isJgwhShow"/>
        </el-form-item>
        <el-form-item label="已转库存数量" prop="zkcsl">
          <el-input v-model="form.zkcsl" placeholder="已转库存数量" :disabled="isJgwhShow"/>
        </el-form-item>
        <el-form-item label="出库数量" prop="cksl">
          <template>
           <el-input-number v-model="form.cksl" :min="1" :max="form.dcksl"  @change="changeVal" />
          </template>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" v-show="!isJgwhShow" >确 定</el-button>
        <el-button type="primary" @click="submitFormCK" v-show="isJgwhShow && !isJgshShow" >出库提交</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 对话框5，订单转库存设置 -->
    <el-dialog :title="title" :visible.sync="openZkc" width="980px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="130px">
         <!--1，计划/订单信息 -->
        <el-form-item label="订单号" prop="ddh" >
          <el-input v-model="form.ddh" placeholder="请输入订单号" :disabled="isJgwhShow" />
        </el-form-item>
        <el-form-item label="物料编码" prop="wlbm">
          <el-input v-model="form.wlbm" placeholder="请输入物料编码" :disabled="isJgwhShow"/>
        </el-form-item>
        <el-form-item label="物料名称" prop="wlmc">
          <el-input v-model="form.wlmc" placeholder="请输入物料名称" :disabled="isJgwhShow"/>
        </el-form-item>
        <el-form-item label="供应商名称" prop="deptName">
          <el-input v-model="form.deptName" placeholder="请输入供应商部门名称" :disabled="isJgwhShow"/>
        </el-form-item>
        <el-form-item label="订单数量" prop="sl">
          <el-input v-model="form.sl" placeholder="订单数量" :disabled="isJgwhShow"/>
        </el-form-item>
        <el-form-item label="已出库数量" prop="ycksl">
          <el-input v-model="form.ycksl" placeholder="已出库数量" :disabled="isJgwhShow"/>
        </el-form-item>
        <el-form-item label="已转库存数量" prop="yzkcsl">
           <el-input v-model="form.yzkcsl" placeholder="已转库存数量" :disabled="isJgwhShow"/>
        </el-form-item>
        <el-form-item label="本次转库存数量" prop="zkcsl">
          <template>
           <el-input-number v-model="form.zkcsl" :min="1" :max="form.zkcsl"  @change="changeVal" />
          </template>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" v-show="!isJgwhShow" >确 定</el-button>
        <el-button type="primary" @click="submitFormZkc" v-show="isJgwhShow && !isJgshShow" >转库存提交</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 对话框6，出货数量设置 -->
    <el-dialog :title="title" :visible.sync="openCh" width="980px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="130px">
         <!--1，计划/订单信息 -->
        <el-form-item label="订单号" prop="ddh" >
          <el-input v-model="form.ddh" placeholder="请输入订单号" :disabled="isJgwhShow" />
        </el-form-item>
        <el-form-item label="物料编码" prop="wlbm">
          <el-input v-model="form.wlbm" placeholder="请输入物料编码" :disabled="isJgwhShow"/>
        </el-form-item>
        <el-form-item label="物料名称" prop="wlmc">
          <el-input v-model="form.wlmc" placeholder="请输入物料名称" :disabled="isJgwhShow"/>
        </el-form-item>
        <el-form-item label="供应商名称" prop="deptName">
          <el-input v-model="form.deptName" placeholder="请输入供应商部门名称" :disabled="isJgwhShow"/>
        </el-form-item>
        <!-- 供货商消库存后，实际订单数量 -->
        <el-form-item label="订单数量(实际)" prop="dhsSjxzddsl">
          <el-input v-model="form.dhsSjxzddsl" placeholder="订单数量" :disabled="isJgwhShow"/>
        </el-form-item>
        <el-form-item label="已出货数量" prop="ychsl">
          <el-input v-model="form.ychsl" placeholder="已出货数量" :disabled="isJgwhShow"/>
        </el-form-item>
        <el-form-item label="出货数量" prop="chsl">
          <template>
           <el-input-number v-model="form.chsl" :min="0" :max="form.dchsl"  @change="changeVal" />
          </template>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" v-show="!isJgwhShow" >确 定</el-button>
        <el-button type="primary" @click="submitFormCh">出货提交</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 计划导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="upload.updateSupport" v-show="false" /> <!-- 是否更新已经存在的业务数据 -->
          </div>
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDdgl, getDdgl, delDdgl, addDdgl, updateDdgl, updateDdglDdrk, updateDdglDdck,updateDdglJgsz,updateDdglCh,updateDdglJgsh,updateDdglRKCK,exportChd,updateDdglZkc } from "@/api/system/ddgl";
import { getToken } from "@/utils/auth";
import { getCurrentDateTime } from "@/utils/dateutil";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
  name: "Ddgl",
  dicts: ['sys_ddzt', 'sys_shzt', 'sys_rkzt', 'sys_ckzt', 'sys_ddlx', 'sys_wllx', 'sys_yw_shifou'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 进销存_计划与订单管理表格数据
      ddglList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 价格设置弹出层
      openJgsz: false,
      // 价格审批弹出层
      openJgsp: false,
      // 入库弹出层
      openRk: false,
      // 供货商出货弹出层
      openCh: false,
      // 出库弹出层
      openCk: false,
      // 订单转库存弹出层
      openZkc: false,
      // 价格维护显示的表单元素
      isJgwhShow : true ,
      // 查看详情显示的表单元素
      isCkxqShow : false ,

      // 价格审核显示的表单元素
      isJgshShow : false ,
      // 发票ID时间范围
      daterangeXdrq: [],
      // 发票ID时间范围
      daterangeJhrq: [],

      // 导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/ddgl/importDataRkCk"
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        ddh: null,
        wlbm: null,
        wlmc: null,
        dw: null,
        sl: null,
        xdrq: null,
        jhrq: null,
        ggyq: null,
        gylx: null,
        jjggx: null,
        zl: null,
        khmc: null,
        dhsDeptId: null,
        deptName: null,
        deptId: null,
        ddbz: null,
        ddlx: null,
        jhshzt1: '1',
        jhsh1shyj: null,
        jhsh1gxsj:null,
        jhshzt2: null,
        jhsh2shyj: null,
        jhsh2gxsj:null,
        wxddid: null,
        ghsdj: null,
        ghszj: null,
        ghsjgbz: null,
        ghsjgwhr: null,
        ghsjgwhsj: null,
        zbjgshzt1: null,
        zbjgsh1shyj: null,
        zbjgsh1shsj: null,
        zbjgshzt2: null,
        zbjgsh2shyj: null,
        zbjgsh2shsj: null,
        wllx: null,
        wlshzt1: null,
        wlsh1shyj: null,
        wlsh1gxsj: null,
        wlshzt2: null,
        wlsh2shyj: null,
        wlsh2gxsj: null,
        rkzt: null,
        rkbz: null,
        rksj: null,
        rkr: null,
        ckzt: null,
        ckbz: null,
        cksj: null,
        ckr: null,
        ddzt: null,
        createby: null,
        createtime: null,
        updateby: null,
        updatetime: null,
        sfsc: null,
        sfykp: null,
        rkfpid: null,
        ckfpid: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        ddh: [
          { required: true, message: "订单号不能为空", trigger: "blur" }
        ],
        createby: [
          { required: true, message: "录入人不能为空", trigger: "blur" }
        ],
        createtime: [
          { required: true, message: "录入时间不能为空", trigger: "blur" }
        ],
        updateby: [
          { required: true, message: "更新人不能为空", trigger: "blur" }
        ],
        updatetime: [
          { required: true, message: "更新时间不能为空", trigger: "blur" }
        ],
        sfsc: [
          { required: true, message: "是否删除,0否1是不能为空", trigger: "change" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    calculateValue(){
      // 自动计算供货商总价
      this.form.ghszj = this.form.ghsdj * this.form.sl ;
    } ,
    /** 查询进销存_计划与订单管理列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeXdrq && '' != this.daterangeXdrq) {
        this.queryParams.params["beginXdrq"] = this.daterangeXdrq[0];
        this.queryParams.params["endXdrq"] = this.daterangeXdrq[1];
      }
      if (null != this.daterangeJhrq && '' != this.daterangeJhrq) {
        this.queryParams.params["beginJhrq"] = this.daterangeJhrq[0];
        this.queryParams.params["endJhrq"] = this.daterangeJhrq[1];
      }
      listDdgl(this.queryParams).then(response => {
        this.ddglList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      // 价格设置弹出层
      this.openJgsz = false;
      // 价格审批弹出层
      this.openJgsp = false;
      // 入库弹出层
      this.openRk = false;
      this.openCh = false;
      // 出库弹出层
      this.openCk = false;
      // 订单转库存弹出层
      this.openZkc = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        ddid: null,
        ddh: null,
        wlbm: null,
        wlmc: null,
        dw: null,
        sl: null,
        xdrq: null,
        jhrq: null,
        ggyq: null,
        gylx: null,
        jjggx: null,
        zl: null,
        khmc: null,
        dhsDeptId: null,
        deptName: null,
        deptId: null,
        ddbz: null,
        ddlx: null,
        jhshzt1: null,
        jhsh1shyj: null,
        jhsh1gxsj:null,
        jhshzt2: null,
        jhsh2shyj: null,
        jhsh2gxsj:null,
        wxddid: null,
        ghsdj: null,
        ghszj: null,
        ghsjgbz: null,
        ghsjgwhr: null,
        ghsjgwhsj: null,
        zbjgshzt1: null,
        zbjgsh1shyj: null,
        zbjgsh1shsj: null,
        zbjgshzt2: null,
        zbjgsh2shyj: null,
        zbjgsh2shsj: null,
        wllx: null,
        wlshzt1: null,
        wlsh1shyj: null,
        wlsh1gxsj: null,
        wlshzt2: null,
        wlsh2shyj: null,
        wlsh2gxsj: null,
        rkzt: null,
        rkbz: null,
        rksj: null,
        rkr: null,
        ckzt: null,
        ckbz: null,
        cksj: null,
        ckr: null,
        ddzt: null,
        createby: null,
        createtime: null,
        updateby: null,
        updatetime: null,
        sfsc: null,
        sfykp: null,
        rkfpid: null,
        rkfpid: null
      };
      this.resetForm("form");
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeXdrq = [];
      this.daterangeJhrq = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.ddid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      // 价格设置弹出层
      this.openJgsz = false;
      // 查看详情
      this.isCkxqShow = false;
      // 价格审批弹出层
      this.openJgsp = false;
      // 入库弹出层
      this.openRk = false;
      // 出库弹出层
      this.openCk = false;
      this.title = "添加订单信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const ddid = row.ddid || this.ids
      getDdgl(ddid).then(response => {
        this.form = response.data;
        this.open = true;
        // 价格设置弹出层
        this.openJgsz = false;
        // 查看详情
        this.isCkxqShow = false;
        // 价格审批弹出层
        this.openJgsp = false;
        // 入库弹出层
        this.openRk = false;
        // 出库弹出层
        this.openCk = false;
        this.title = "修改订单信息";
      });
    },

    /** 详情按钮操作 */
    handleUpdateXq(row) {
       this.reset();
       const ddid = row.ddid || this.ids
       getDdgl(ddid).then(response => {
         this.form = response.data;
         this.open = true;
         // 价格设置弹出层
         this.openJgsz = false;
         // 查看详情
         this.isCkxqShow = true;
         // 价格审批弹出层
         this.openJgsp = false;
         // 入库弹出层
         this.openRk = false;
         // 出库弹出层
         this.openCk = false;
         this.title = "订单详情";
       });
    },
    /** 价格设置按钮操作 */
    handleUpdateJgsz(row) {
      this.isJgwhShow=true;// 价格维护设置,全局禁止编辑
      this.isJgshShow=true;// true 禁用  false 启用
      this.reset();
      const ddid = row.ddid || this.ids
      getDdgl(ddid).then(response => {
        this.form = response.data;
        this.open = false;
        // 价格设置弹出层
        this.openJgsz = true;
        // 价格审批弹出层
        this.openJgsp = false;
        // 入库弹出层
        this.openRk = false;
        // 出库弹出层
        this.openCk = false;
        this.title = "供货商价格设置";
      });
    },
    /** 价格审批按钮操作 */
    handleUpdateJgsp(row) {
      //供货商已维护了商品价格后才可审批
      if(!row.ghsdj || !row.ghszj){
        //this.$modal.msgSuccess("供应商暂未维护商品价格，请催促供应商完成商品价格维护后再进行审核！");
        this.$message({
          message: '供应商暂未维护商品价格，请催促供应商完成商品价格维护后再进行审核！',
          type: 'warning'
        });
        return;
      }
      this.reset();
     this.isJgwhShow=true;// 价格维护设置,全局禁止编辑
     this.isJgshShow=false;// true 禁用  false 启用
      const ddid = row.ddid || this.ids
      getDdgl(ddid).then(response => {
        this.form = response.data;
        this.open = false;
        // 价格设置弹出层
        this.openJgsz = true;
        // 价格审批弹出层
        //this.openJgsp = true;
        // 入库弹出层
        this.openRk = false;
        // 出库弹出层
        this.openCk = false;
        this.title = "总部价格审核";
      });
    },
    //强制计数器
    changeVal(){
      this.$forceUpdate();//解决el-input-number点击计数器失效问题
    },
    /** 入库按钮操作 */
    handleUpdateRk(row) {
       const ddids = row.ddid || this.ids;
       const ddh = row.ddh;
       const wlbm = row.wlbm;
       const wlmc = row.wlmc;
       const gysmc = row.deptName;
       this.form.ddid=row.ddid;
       this.form.ddh=row.ddh;
       this.form.wlbm=row.wlbm;
       this.form.wlid= row.wlid;
       this.form.wlmc=row.wlmc;
       this.form.deptName = row.deptName;
       this.form.sl = row.sl;     //总库存数量
       this.form.yrksl = row.rksl;
       this.form.rksl = row.sl - row.rksl;  //本次入库数量
       this.form.drksl = row.sl - row.rksl; //待入库数量
       this.title="订单入库";
       // 总部价格审批完成后才可入库
       const zbjgshzt1 = row.zbjgshzt1;
       /* if(!zbjgshzt1){
        this.$message({
          message: '总部价格审批完成后才可入库哦~',
          type: 'warning'
        });
        return ;
       } */
        // 入库弹出层
       this.openRk = true;
       /* this.$modal.confirm('是否确认入库订单号为"' + ddh + '",物料编码为"' + wlbm + '",物料名称为"' + wlmc + '",供应商为"' + gysmc + '"的数据项？').then(function() {
          updateDdglDdrk(row).then(response => {
            this.getList();
          });
       }).then(() => {
         this.getList();
         this.$modal.msgSuccess("入库成功");
       }).catch(() => {}); */
    },
    /** 出库按钮操作 */
    handleUpdateCk(row) {
       const ddids = row.ddid || this.ids;
       const ddh = row.ddh;
       const wlbm = row.wlbm;
       const wlmc = row.wlmc;
       const gysmc = row.deptName;
       this.form.ddid=row.ddid;
       this.form.ddh=row.ddh;
       this.form.wlbm=row.wlbm;
       this.form.wlid= row.wlid;
       this.form.wlmc=row.wlmc;
       this.form.deptName = row.deptName;
       this.form.sl = row.sl;     //总库存数量
       this.form.yrksl = row.rksl;
       this.form.ycksl = row.cksl;
       this.form.zkcsl = row.zkcsl; //已转库存数量
       // this.form.rksl = row.sl - row.rksl;  //本次入库数量
       // this.form.drksl = row.sl - row.rksl; //待入库数量
       this.form.cksl = row.dcksl;  //本次出库数量
       this.form.dcksl = row.dcksl; //待出库数量
       this.title="订单出库";
        // 出库弹出层
       this.openCk = true;
    },
    /** 转库存按钮操作 */
    handleUpdateZkc(row) {
       const ddids = row.ddid || this.ids;
       const ddh = row.ddh;
       const wlbm = row.wlbm;
       const wlmc = row.wlmc;
       const gysmc = row.deptName;
       this.form.ddid=row.ddid;
       this.form.ddh=row.ddh;
       this.form.wlbm=row.wlbm;
       this.form.wlid= row.wlid;
       this.form.wlmc=row.wlmc;
       this.form.deptName = row.deptName;
       this.form.sl = row.sl;     //总库存数量
       this.form.yrksl = row.rksl;
       this.form.ycksl = row.cksl;
       this.form.cksl = row.cksl;  //已出库数量
        this.form.yzkcsl = row.zkcsl; //已转库存数量
       this.form.zkcsl = row.sl - row.cksl - row.zkcsl; //本次最大转库存数量
       this.title="订单转库存";
        // 订单转库存弹出层
       this.openZkc = true;
    },
    /** 出货按钮操作 */
    handleUpdateCh(row) {
       const ddids = row.ddid || this.ids;
       const ddh = row.ddh;
       const wlbm = row.wlbm;
       const wlmc = row.wlmc;
       const gysmc = row.deptName;
       this.form.ddid=row.ddid;
       this.form.ddh=row.ddh;
       this.form.wlbm=row.wlbm;
       this.form.wlid= row.wlid;
       this.form.wlmc=row.wlmc;

       this.form.sl = row.sl;     //总订单数量
       this.form.dhsSjxzddsl = row.dhsSjxzddsl; //消库存后实际新增订单数量
       this.form.deptId = row.deptId; //供货商部门ID
       this.form.deptName = row.deptName;//供货商部门名称
       this.form.dhsDeptId = row.dhsDeptId;
       this.form.dhsDeptName = row.dhsDeptName;
       //this.form.yrksl = row.rksl;
       //this.form.rksl = row.sl - row.rksl;  //本次入库数量
       //this.form.drksl = row.sl - row.rksl; //待入库数量
       //供货商出货
       this.form.ychsl = row.chsl; // 已出货数量
       this.form.chsl = row.dhsSjxzddsl - row.chsl; //本次出货数量
       this.form.dchsl = row.dhsSjxzddsl - row.chsl;//待出货数量
       this.title="订单出货";
        // 入库弹出层
       this.openCh = true;
    },

    /** 出库按钮操作 */
    handleUpdateCkBak(row) {
       const ddids = row.ddid || this.ids;
       const ddh = row.ddh;
       const wlbm = row.wlbm;
       const wlmc = row.wlmc;
       const gysmc = row.deptName;
       // 总部价格审批完成后才可入库
       /* const rkzt = row.rkzt;
       if(!rkzt){
        this.$message({
          message: '请先完成入库后才可出库哦~',
          type: 'warning'
        });
        return ;
       } */
        this.$modal.confirm('是否确认出库订单号为"' + ddh + '",物料编码为"' + wlbm + '",物料名称为"' + wlmc + '",供应商为"' + gysmc + '"的数据项？').then(function() {
          updateDdglDdck(row).then(response => {
            this.getList();
          });
       }).then(() => {
         this.getList();
         this.$modal.msgSuccess("入库成功");
       }).catch(() => {});
    },
    /** 删除按钮操作 */
    handleUpdateRk11(row) {
      const ddids = row.ddid || this.ids;
      this.$modal.confirm('是否确认删除所选订单信息？').then(function() {
        //return delDdgl(ddids);
       return 1;
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.ddid != null) {
            updateDdgl(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
               this.openJgsz = false;
              this.getList();
            });
          } else {
            addDdgl(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 价格设置按钮 */
    submitFormJgsz() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.ddid != null) {
            updateDdglJgsz(this.form).then(response => {
              this.$modal.msgSuccess("价格设置成功");
              this.open = false;
               this.openJgsz = false;
              this.getList();
            });
          } else {
            this.$modal.msgSuccess("数据ddid值不合法，请刷新页面或重新登录后重试！");
          }
        }
      });
    },
    /** 出货提交按钮 */
    submitFormCh() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.ddid != null) {
            /* if(this.form.chsl > this.form.dhsSjxzddsl){
              this.$message({
                message: '出货数量不允许超过订单数量！',
                type: 'warning'
              });
              return ;
            } */
            updateDdglCh(this.form).then(response => {
              this.$modal.msgSuccess("出货成功");
              this.open = false;
              this.openJgsz = false;
               this.openCh = false;
              this.getList();
            });
          } else {
            this.$modal.msgSuccess("数据ddid值不合法，请刷新页面或重新登录后重试！");
          }
        }
      });
    },
    /** 价格审核按钮 */
    submitFormJgsh() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.ddid != null) {
            updateDdglJgsh(this.form).then(response => {
              this.$modal.msgSuccess("价格审核成功");
              this.open = false;
               this.openJgsz = false;
              this.getList();
            });
          } else {
            this.$modal.msgSuccess("数据ddid值不合法，请刷新页面或重新登录后重试！");
          }
        }
      });
    },
    /** 入库设置按钮 */
    submitFormRK() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.ddid != null) {
            //updateDdglRKCK(this.form).then(response => {
            updateDdglDdrk(this.form).then(response => {
              this.$modal.msgSuccess("入库成功");
              this.getList();
            });
            this.open = false;
            this.openJgsz = false;
            this.openRK = false;
          } else {
            this.$modal.msgSuccess("数据ddid值不合法，请刷新页面或重新登录后重试！");
          }
        }
      });
    },
    /** 出库设置按钮 */
    submitFormCK() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.ddid != null) {
            updateDdglDdck(this.form).then(response => {
              this.$modal.msgSuccess("出库成功");
              this.getList();
            });
            this.open = false;
            this.openJgsz = false;
            this.openCK = false;
          } else {
            this.$modal.msgSuccess("数据ddid值不合法，请刷新页面或重新登录后重试！");
          }
        }
      });
    },
    /** 转库存提交按钮 */
    submitFormZkc() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.ddid != null) {
            updateDdglZkc(this.form).then(response => {
              this.$modal.msgSuccess("转库存成功");
              this.getList();
            });
            this.open = false;
            this.openJgsz = false;
            this.openZkc = false;
          } else {
            this.$modal.msgSuccess("数据ddid值不合法，请刷新页面或重新登录后重试！");
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ddids = row.ddid || this.ids;
      this.$modal.confirm('是否确认删除所选订单信息？').then(function() {
        return delDdgl(ddids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出出货单按钮操作 */
    exportChd(row) {
      const ddids = row.ddid || this.ids;
      if(ddids==''){
        this.$modal.msgError("请选择一条数据");
        return;
      }
      let _that=this;
      this.$modal.confirm('如需修改出货数量，请提前修改后导出出货单！是否继续确认导出出货单？').then(function() {
        /*chdPdf(kcids).then(response => {
          this.$modal.msgSuccess("导出成功");
          this.getList();
        });*/
        _that.download('ddgl/exportPdf/'+ddids, {
        }, `出货单_${new Date().getTime()}.pdf`)
      });
    },
    /** 导出订单按钮操作 */
    handleExport() {
      this.download('ddgl/exportDd', {
        ...this.queryParams
      }, `订单管理_${new Date().getTime()}.xlsx`)
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "出入库导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('ddgl/exportDd', {
      }, `订单出入库导入_${new Date().getTime()}.xlsx`)
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    }
  }
};
</script>
<style scoped>
@import "../../assets/styles/index.css";
::v-deep .el-popper .popper__arrow::after,
::v-deep .el-popper .popper__arrow {
	display: none;
}
::v-deep .el-upload-list {
	/* display: none; */
}
.el-icon-circle-close {
	font-size: 16px;
	color: #e65e5e;
	cursor: pointer;
	position: relative;
	top: 2px;
	left: 5px;
}
</style>
